package com.ostrich.module_community.attention.adapter

import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.databinding.DataBindingUtil
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ostrich.library_common.utils.LoggerUtils
import com.ostrich.library_video.views.CoverVideoPlayerView
import com.ostrich.module_community.R
import com.ostrich.module_community.attention.entity.AttentionEntity
import com.ostrich.module_community.databinding.CommunityItemAttentionCardViewBinding
import com.shuyu.gsyvideoplayer.utils.GSYVideoHelper

/**
 * @Author : yaotianxue
 * @Time : On 2023/10/31 15:21
 * @Description : AttentionAdapter
 */
class AttentionAdapter(
    val gsyVideoHelper: GSYVideoHelper,val gsyVideoHelperBuilder: GSYVideoHelper.GSYVideoHelperBuilder, private val layoutResId: Int,
    data: MutableList<AttentionEntity>,
):BaseQuickAdapter<AttentionEntity,BaseViewHolder>(layoutResId,data) {
    companion object{
        const val TAG = "AA"
    }
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        DataBindingUtil.bind<CommunityItemAttentionCardViewBinding>(viewHolder.itemView)
    }


    override fun convert(holder: BaseViewHolder, item: AttentionEntity) {
        holder.getBinding<CommunityItemAttentionCardViewBinding>()?.viewModel = item
        holder.getBinding<CommunityItemAttentionCardViewBinding>()?.executePendingBindings()


        //封面+视频资源
        val imageView = ImageView(context)
        Glide.with(context).load(item.data.content.data.cover.feed)
            .transform(CenterCrop())
            .into(imageView)

        val startButton = holder.getView<ImageView>(R.id.list_item_btn)
        val videoContainer = holder.getView<FrameLayout>(R.id.list_item_container)
        gsyVideoHelper.addVideoPlayer(holder.adapterPosition,
            imageView,
            TAG,
            videoContainer,
            startButton)
    }
}